const userApi = require('./api/userApi')
const data = require('./api/data.js')

const fs = require('fs')
const path = require('path')
const bodyParser = require('body-parser')
const express = require('express')

const app = express()
//设置运行跨域请求
app.all('*', function (req, res, next) {
  res.header('Access-Control-Allow-Origin', '*')
  res.header('Access-Control-Allow-Headers', 'content-type')
  res.header('Access-Control-Allow-Methods', 'POST,GET')
  if (req.method.toLocaleLowerCase() == 'options') {
    res.send(200)
  } else {
    next()
  }
})

app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }))

// 后端api路由
app.use('/api/user', userApi)
app.use('/api/data', data)

app.listen(3000, function () {
  console.log('port:3000running...')
})
